﻿using System;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using System.Threading;

namespace Mono.Cecil
{
	// Token: 0x0200001C RID: 28
	public class AssemblyNameReference : IMetadataScope, IMetadataTokenProvider
	{
		// Token: 0x1700002B RID: 43
		// (get) Token: 0x0600011B RID: 283 RVA: 0x0000D334 File Offset: 0x0000B534
		// (set) Token: 0x0600011C RID: 284 RVA: 0x00002CAC File Offset: 0x00000EAC
		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				this.name = value;
				this.full_name = null;
			}
		}

		// Token: 0x1700002C RID: 44
		// (get) Token: 0x0600011D RID: 285 RVA: 0x0000D34C File Offset: 0x0000B54C
		// (set) Token: 0x0600011E RID: 286 RVA: 0x00002CBD File Offset: 0x00000EBD
		public string Culture
		{
			get
			{
				return this.culture;
			}
			set
			{
				this.culture = value;
				this.full_name = null;
			}
		}

		// Token: 0x1700002D RID: 45
		// (get) Token: 0x0600011F RID: 287 RVA: 0x0000D364 File Offset: 0x0000B564
		// (set) Token: 0x06000120 RID: 288 RVA: 0x00002CCE File Offset: 0x00000ECE
		public Version Version
		{
			get
			{
				return this.version;
			}
			set
			{
				this.version = Mixin.CheckVersion(value);
				this.full_name = null;
			}
		}

		// Token: 0x1700002E RID: 46
		// (get) Token: 0x06000121 RID: 289 RVA: 0x0000D37C File Offset: 0x0000B57C
		// (set) Token: 0x06000122 RID: 290 RVA: 0x00002CE4 File Offset: 0x00000EE4
		public AssemblyAttributes Attributes
		{
			get
			{
				return (AssemblyAttributes)this.attributes;
			}
			set
			{
				this.attributes = (uint)value;
			}
		}

		// Token: 0x1700002F RID: 47
		// (get) Token: 0x06000123 RID: 291 RVA: 0x0000D394 File Offset: 0x0000B594
		// (set) Token: 0x06000124 RID: 292 RVA: 0x00002CEE File Offset: 0x00000EEE
		public bool HasPublicKey
		{
			get
			{
				return this.attributes.GetAttributes(1U);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(1U, value);
			}
		}

		// Token: 0x17000030 RID: 48
		// (get) Token: 0x06000125 RID: 293 RVA: 0x0000D3B4 File Offset: 0x0000B5B4
		// (set) Token: 0x06000126 RID: 294 RVA: 0x00002D04 File Offset: 0x00000F04
		public bool IsSideBySideCompatible
		{
			get
			{
				return this.attributes.GetAttributes(0U);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(0U, value);
			}
		}

		// Token: 0x17000031 RID: 49
		// (get) Token: 0x06000127 RID: 295 RVA: 0x0000D3D4 File Offset: 0x0000B5D4
		// (set) Token: 0x06000128 RID: 296 RVA: 0x00002D1A File Offset: 0x00000F1A
		public bool IsRetargetable
		{
			get
			{
				return this.attributes.GetAttributes(256U);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(256U, value);
			}
		}

		// Token: 0x17000032 RID: 50
		// (get) Token: 0x06000129 RID: 297 RVA: 0x0000D3F8 File Offset: 0x0000B5F8
		// (set) Token: 0x0600012A RID: 298 RVA: 0x00002D34 File Offset: 0x00000F34
		public bool IsWindowsRuntime
		{
			get
			{
				return this.attributes.GetAttributes(512U);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(512U, value);
			}
		}

		// Token: 0x17000033 RID: 51
		// (get) Token: 0x0600012B RID: 299 RVA: 0x0000D41C File Offset: 0x0000B61C
		// (set) Token: 0x0600012C RID: 300 RVA: 0x00002D4E File Offset: 0x00000F4E
		public byte[] PublicKey
		{
			get
			{
				return this.public_key ?? Empty<byte>.Array;
			}
			set
			{
				this.public_key = value;
				this.HasPublicKey = !this.public_key.IsNullOrEmpty<byte>();
				this.public_key_token = null;
				this.full_name = null;
			}
		}

		// Token: 0x17000034 RID: 52
		// (get) Token: 0x0600012D RID: 301 RVA: 0x0000D440 File Offset: 0x0000B640
		// (set) Token: 0x0600012E RID: 302 RVA: 0x00002D7B File Offset: 0x00000F7B
		public byte[] PublicKeyToken
		{
			get
			{
				bool flag = this.public_key_token == null && !this.public_key.IsNullOrEmpty<byte>();
				if (flag)
				{
					byte[] array = this.HashPublicKey();
					byte[] array2 = new byte[8];
					Array.Copy(array, array.Length - 8, array2, 0, 8);
					Array.Reverse(array2, 0, 8);
					Interlocked.CompareExchange<byte[]>(ref this.public_key_token, array2, null);
				}
				return this.public_key_token ?? Empty<byte>.Array;
			}
			set
			{
				this.public_key_token = value;
				this.full_name = null;
			}
		}

		// Token: 0x0600012F RID: 303 RVA: 0x0000D4B4 File Offset: 0x0000B6B4
		private byte[] HashPublicKey()
		{
			AssemblyHashAlgorithm assemblyHashAlgorithm = this.hash_algorithm;
			AssemblyHashAlgorithm assemblyHashAlgorithm2 = assemblyHashAlgorithm;
			HashAlgorithm hashAlgorithm;
			if (assemblyHashAlgorithm2 != AssemblyHashAlgorithm.MD5)
			{
				hashAlgorithm = SHA1.Create();
			}
			else
			{
				hashAlgorithm = MD5.Create();
			}
			byte[] result;
			using (hashAlgorithm)
			{
				result = hashAlgorithm.ComputeHash(this.public_key);
			}
			return result;
		}

		// Token: 0x17000035 RID: 53
		// (get) Token: 0x06000130 RID: 304 RVA: 0x0000D514 File Offset: 0x0000B714
		public virtual MetadataScopeType MetadataScopeType
		{
			get
			{
				return MetadataScopeType.AssemblyNameReference;
			}
		}

		// Token: 0x17000036 RID: 54
		// (get) Token: 0x06000131 RID: 305 RVA: 0x0000D528 File Offset: 0x0000B728
		public string FullName
		{
			get
			{
				bool flag = this.full_name != null;
				string result;
				if (flag)
				{
					result = this.full_name;
				}
				else
				{
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.Append(this.name);
					stringBuilder.Append(", ");
					stringBuilder.Append("Version=");
					stringBuilder.Append(this.version.ToString(4));
					stringBuilder.Append(", ");
					stringBuilder.Append("Culture=");
					stringBuilder.Append(string.IsNullOrEmpty(this.culture) ? "neutral" : this.culture);
					stringBuilder.Append(", ");
					stringBuilder.Append("PublicKeyToken=");
					byte[] publicKeyToken = this.PublicKeyToken;
					bool flag2 = !publicKeyToken.IsNullOrEmpty<byte>() && publicKeyToken.Length != 0;
					if (flag2)
					{
						for (int i = 0; i < publicKeyToken.Length; i++)
						{
							stringBuilder.Append(publicKeyToken[i].ToString("x2"));
						}
					}
					else
					{
						stringBuilder.Append("null");
					}
					bool isRetargetable = this.IsRetargetable;
					if (isRetargetable)
					{
						stringBuilder.Append(", ");
						stringBuilder.Append("Retargetable=Yes");
					}
					Interlocked.CompareExchange<string>(ref this.full_name, stringBuilder.ToString(), null);
					result = this.full_name;
				}
				return result;
			}
		}

		// Token: 0x06000132 RID: 306 RVA: 0x0000D684 File Offset: 0x0000B884
		public static AssemblyNameReference Parse(string fullName)
		{
			bool flag = fullName == null;
			if (flag)
			{
				throw new ArgumentNullException("fullName");
			}
			bool flag2 = fullName.Length == 0;
			if (flag2)
			{
				throw new ArgumentException("Name can not be empty");
			}
			AssemblyNameReference assemblyNameReference = new AssemblyNameReference();
			string[] array = fullName.Split(new char[]
			{
				','
			});
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				bool flag3 = i == 0;
				if (flag3)
				{
					assemblyNameReference.Name = text;
				}
				else
				{
					string[] array2 = text.Split(new char[]
					{
						'='
					});
					bool flag4 = array2.Length != 2;
					if (flag4)
					{
						throw new ArgumentException("Malformed name");
					}
					string text2 = array2[0].ToLowerInvariant();
					string a = text2;
					if (!(a == "version"))
					{
						if (!(a == "culture"))
						{
							if (a == "publickeytoken")
							{
								string text3 = array2[1];
								bool flag5 = text3 == "null";
								if (!flag5)
								{
									assemblyNameReference.PublicKeyToken = new byte[text3.Length / 2];
									for (int j = 0; j < assemblyNameReference.PublicKeyToken.Length; j++)
									{
										assemblyNameReference.PublicKeyToken[j] = byte.Parse(text3.Substring(j * 2, 2), NumberStyles.HexNumber);
									}
								}
							}
						}
						else
						{
							assemblyNameReference.Culture = ((array2[1] == "neutral") ? "" : array2[1]);
						}
					}
					else
					{
						assemblyNameReference.Version = new Version(array2[1]);
					}
				}
			}
			return assemblyNameReference;
		}

		// Token: 0x17000037 RID: 55
		// (get) Token: 0x06000133 RID: 307 RVA: 0x0000D834 File Offset: 0x0000BA34
		// (set) Token: 0x06000134 RID: 308 RVA: 0x00002D8C File Offset: 0x00000F8C
		public AssemblyHashAlgorithm HashAlgorithm
		{
			get
			{
				return this.hash_algorithm;
			}
			set
			{
				this.hash_algorithm = value;
			}
		}

		// Token: 0x17000038 RID: 56
		// (get) Token: 0x06000135 RID: 309 RVA: 0x0000D84C File Offset: 0x0000BA4C
		// (set) Token: 0x06000136 RID: 310 RVA: 0x00002D96 File Offset: 0x00000F96
		public virtual byte[] Hash
		{
			get
			{
				return this.hash;
			}
			set
			{
				this.hash = value;
			}
		}

		// Token: 0x17000039 RID: 57
		// (get) Token: 0x06000137 RID: 311 RVA: 0x0000D864 File Offset: 0x0000BA64
		// (set) Token: 0x06000138 RID: 312 RVA: 0x00002DA0 File Offset: 0x00000FA0
		public MetadataToken MetadataToken
		{
			get
			{
				return this.token;
			}
			set
			{
				this.token = value;
			}
		}

		// Token: 0x06000139 RID: 313 RVA: 0x00002DAA File Offset: 0x00000FAA
		internal AssemblyNameReference()
		{
			this.version = Mixin.ZeroVersion;
			this.token = new MetadataToken(TokenType.AssemblyRef);
		}

		// Token: 0x0600013A RID: 314 RVA: 0x00002DCF File Offset: 0x00000FCF
		public AssemblyNameReference(string name, Version version)
		{
			Mixin.CheckName(name);
			this.name = name;
			this.version = Mixin.CheckVersion(version);
			this.hash_algorithm = AssemblyHashAlgorithm.None;
			this.token = new MetadataToken(TokenType.AssemblyRef);
		}

		// Token: 0x0600013B RID: 315 RVA: 0x0000D87C File Offset: 0x0000BA7C
		public override string ToString()
		{
			return this.FullName;
		}

		// Token: 0x04000078 RID: 120
		private string name;

		// Token: 0x04000079 RID: 121
		private string culture;

		// Token: 0x0400007A RID: 122
		private Version version;

		// Token: 0x0400007B RID: 123
		private uint attributes;

		// Token: 0x0400007C RID: 124
		private byte[] public_key;

		// Token: 0x0400007D RID: 125
		private byte[] public_key_token;

		// Token: 0x0400007E RID: 126
		private AssemblyHashAlgorithm hash_algorithm;

		// Token: 0x0400007F RID: 127
		private byte[] hash;

		// Token: 0x04000080 RID: 128
		internal MetadataToken token;

		// Token: 0x04000081 RID: 129
		private string full_name;
	}
}
